package com.hhx.test_library.ui;

import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.hhx.baselibrary.base.BaseMVPActivity;
import com.hhx.baselibrary.bean.BaseResponse;
import com.hhx.baselibrary.constants.Constants;
import com.hhx.baselibrary.widget.ThumbnailView;
import com.hhx.test_library.R;
import com.hhx.test_library.mvp.contract.AContract;
import com.hhx.test_library.mvp.presenter.APresenter;

import java.util.HashMap;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.ObservableTransformer;

public class LoginActivity extends BaseMVPActivity<AContract.View, AContract.Presenter> implements AContract.View {

    @BindView(R.id.iv_header_left)
    ThumbnailView ivHeaderLeft;
    @BindView(R.id.tv_header_title)
    TextView tvHeaderTitle;
    @BindView(R.id.iv_header_right)
    ThumbnailView ivHeaderRight;
    @BindView(R.id.btn_login_in)
    Button btnLoginIn;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_login;
    }

    @Override
    protected void initView() {
        setHeaderImage(Constants.Position.LEFT, R.drawable.ic_back, false, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        setHeaderTitle("登录");
    }

    @OnClick(R.id.btn_login_in)
    public void OnLoginClick(View view) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("phone", "18245083860");
        map.put("password", "13156");
        getPresenter().login(map, true, true);
    }

    @Override
    public void initPresenter() {

    }

    @Override
    public AContract.Presenter createPresenter() {
        return new APresenter(this);
    }

    @Override
    public AContract.View createView() {
        return this;
    }

    @Override
    public void refreshSuccess(BaseResponse baseResponse) {
        if (baseResponse.getCode() == 1) {
            showShortToast(baseResponse.getMsg());
        } else {
            showShortToast(baseResponse.getMsg());
        }
    }

    @Override
    public void refreshFailed(String msg) {

    }

    @Override
    public <T> ObservableTransformer<T, T> bindLifecycle() {
        return this.bindToLifecycle();
    }

}
